import * as React from 'react'; import { View, ViewProps } from '@aws-amplify/ui-react'; import { ViewPropControlsProps } from './ViewPropControls'; import { demoState } from '@/utils/demoState'; interface UseViewProps { (initialValues: ViewProps): ViewPropControlsProps; } export const useViewProps: UseViewProps = (initialValues) => { const [ariaLabel, setAriaLabel] = React.useState( initialValues.ariaLabel ); const [width, setWidth] = React.useState( initialValues.width ); const [maxWidth, setMaxWidth] = React.useState( initialValues.maxWidth ); const [height, setHeight] = React.useState( initialValues.height ); const [color, setColor] = React.useState( initialValues.color ); const [backgroundColor, setBackgroundColor] = React.useState< ViewProps['backgroundColor'] >(initialValues.backgroundColor); const [boxShadow, setBoxShadow] = React.useState( initialValues.boxShadow ); const [padding, setPadding] = React.useState( initialValues.padding ); const [border, setBorder] = React.useState( initialValues.border ); const [borderRadius, setBorderRadius] = React.useState< ViewProps['borderRadius'] >(initialValues.borderRadius); const [as, setAsElementType] = React.useState( initialValues.as ); React.useEffect(() => { demoState.set(View.displayName, { ariaLabel, width, maxWidth, height, color, backgroundColor, boxShadow, padding, border, borderRadius, as, }); }, [ ariaLabel, width, maxWidth, height, color, backgroundColor, boxShadow, padding, border, borderRadius, as, ]); return React.useMemo( () => ({ ariaLabel, setAriaLabel, width, setWidth, maxWidth, setMaxWidth, height, setHeight, color, setColor, backgroundColor, setBackgroundColor, boxShadow, setBoxShadow, padding, setPadding, border, setBorder, borderRadius, setBorderRadius, as, setAsElementType, }), [ ariaLabel, setAriaLabel, width, setWidth, maxWidth, setMaxWidth, height, setHeight, color, setColor, backgroundColor, setBackgroundColor, boxShadow, setBoxShadow, padding, setPadding, border, setBorder, borderRadius, setBorderRadius, as, setAsElementType, ] ); };